﻿Imports System.ComponentModel
Imports DevExpress.Skins
Imports DevExpress.LookAndFeel
Imports DevExpress.UserSkins
Imports DevExpress.XtraBars
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraBars.Helpers


Public Class frmMain
    Sub New()
        InitializeComponent()
        ribbonControl.SelectedPage = XeRibbonPage
    End Sub

    Private Sub btnThoat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnThoat.ItemClick
        Close()
    End Sub

    Private Sub ribbonControl_SelectedPageChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ribbonControl.SelectedPageChanged
        Select Case ribbonControl.SelectedPage.PageIndex
            Case 0
                XePanel.Visible = True
                KhachHangPanel.Visible = False
                DanhSachPNPanel.Visible = False
                HoaDonPanel.Visible = False
                KhoPanel.Visible = False
                XePanel.Dock = DockStyle.Fill
                Exit Select
            Case 1
                XePanel.Visible = False
                KhachHangPanel.Visible = True
                DanhSachPNPanel.Visible = False
                HoaDonPanel.Visible = False
                KhoPanel.Visible = False
                KhachHangPanel.Dock = DockStyle.Fill
                Exit Select
            Case 2
                XePanel.Visible = False
                KhachHangPanel.Visible = False
                DanhSachPNPanel.Visible = False
                HoaDonPanel.Visible = False
                KhoPanel.Visible = True
                KhoPanel.Dock = DockStyle.Fill
                Exit Select
            Case 3
                XePanel.Visible = False
                KhachHangPanel.Visible = False
                DanhSachPNPanel.Visible = False
                HoaDonPanel.Visible = False
                KhoPanel.Visible = False
                Exit Select
        End Select
    End Sub

    Private Sub btnThoat1_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnThoat1.ItemClick
        Close()
    End Sub

    Private Sub btnThoatK_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnThoatK.ItemClick
        Close()
    End Sub

    Private Sub btnPhieuNhapKho_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnPhieuNhapKho.ItemClick
        Dim frm As New frmPhieuNhapKho
        frm.ShowDialog()
    End Sub

    Private Sub btnPhieuXuatKho_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnPhieuXuatKho.ItemClick
        Dim frm As New frmPhieuXuatKho
        frm.ShowDialog()
    End Sub

    Private Sub LapBaoCaoItem_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs)
        Dim frm As New frmBaoCaoThang
        frm.ShowDialog()
    End Sub

    Private Sub BarButtonItem1_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
        Close()
    End Sub

    Dim dtDSXe As New DataTable
#Region "Các hàm thao tác với XeDTO"

    'Hàm load danh sách tất cả các xe lên grCtrlXe
    Public Sub _LoadDsXe()

        Dim _xeBUS As New XeBUS()
        dtDSXe = _xeBUS._LayDsXe()
        grCtrlXe.DataSource = dtDSXe

    End Sub

#End Region

#Region "Các hàm thao tác với KhachHangDTO"

    'Hàm load danh sách tất cả khách hàng lên grCtrlKhachHang
    Public Sub _LoadDsKH()

        Dim _khachHangBUS As New KhachHangBUS()
        grCtrlKhachHang.DataSource = _khachHangBUS._LayDsKH()

    End Sub

#End Region


    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        _LoadDsXe()
        _LoadDsKH()

    End Sub

    Private Sub btnHienThiDSXe_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnHienThiDSXe.ItemClick
        XePanel.Visible = True
        KhachHangPanel.Visible = False
        DanhSachPNPanel.Visible = False
        HoaDonPanel.Visible = False
        KhoPanel.Visible = False
        grCtrlHoaDon.Visible = False
        grCtrlXe.Visible = True
        _LoadDsXe()

    End Sub

    Private Sub btnHienThiDSKH_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnHienThiDSKH.ItemClick
        XePanel.Visible = False
        KhachHangPanel.Visible = True
        DanhSachPNPanel.Visible = False
        HoaDonPanel.Visible = False
        KhoPanel.Visible = False
        _LoadDsKH()

    End Sub

    Private Sub PhieuNhapXeItem_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles PhieuNhapXeItem.LinkClicked
        Dim frm As New frmPhieuNhapXe
        frm.ShowDialog()
        'Sau khi đóng form PhieuNhapXe thì load lại danh sách xe sau khi nhập xe
        _LoadDsXe()
    End Sub

    Private Sub LapHoaDonItem_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles LapHoaDonItem.LinkClicked
        Dim frm As New frmHoaDon
        frm.ShowDialog()
    End Sub

    Private Sub DanhSachPNItem_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles DanhSachPNItem.LinkClicked
        XePanel.Visible = False
        KhachHangPanel.Visible = False
        DanhSachPNPanel.Visible = True
        HoaDonPanel.Visible = False
        KhoPanel.Visible = False
        DanhSachPNPanel.Dock = DockStyle.Fill
    End Sub

    Private Sub DSHDItem_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles DSHDItem.LinkClicked
        XePanel.Visible = False
        KhachHangPanel.Visible = False
        DanhSachPNPanel.Visible = False
        HoaDonPanel.Visible = True
        KhoPanel.Visible = False
        HoaDonPanel.Dock = DockStyle.Fill
    End Sub

    Private Sub btnHuyCapNhat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnHuyCapNhat.ItemClick
        _LoadDsXe()
    End Sub

    Private Sub btnCapNhat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnCapNhat.ItemClick

        Try
            For Each row As DataRow In dtDSXe.Rows
                If row.RowState = DataRowState.Modified Then
                    Dim xe As New XeDTO
                    xe.m_strMaXe = row("MaXe").ToString()
                    xe.m_strTenXe = row("TenXe").ToString()
                    xe.m_iSoLuong = Integer.Parse(row("SoLuong"))
                    xe.m_dDonGia = Double.Parse(row("DonGia"))
                    Dim a As Integer = XeBUS.CapNhatXe(xe)
                    If a = 1 Then
                        MessageBox.Show("Cập nhật thành công.")
                    End If
                End If
            Next
        Catch ex As Exception
            MessageBox.Show("Cập nhật thất bại.")
        End Try

    End Sub

    Private Sub btnDSXeKho_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDSXeKho.ItemClick
        XePanel.Visible = False
        KhachHangPanel.Visible = False
        DanhSachPNPanel.Visible = False
        HoaDonPanel.Visible = False
        KhoPanel.Visible = True
    End Sub

    Private Sub btnTraCuu_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnTraCuu.ItemClick
        Dim frmTimKiem As New frmTimKiemXe
        frmTimKiem.ShowDialog()
    End Sub
End Class
